package cn.zhaoguang.usedcar.main.controller;

import cn.zhaoguang.usedcar.common.http.ResultVO;
import cn.zhaoguang.usedcar.main.entity.Carousel;
import cn.zhaoguang.usedcar.main.entity.Recommend;
import cn.zhaoguang.usedcar.main.service.RecommendService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Description
 * @Author zhaoguang
 * @Date 2021/7/7 17:41
 */
@RestController
@RequestMapping("/recommend")
@Api(tags = "推荐车辆控制器")
public class RecommendController {

    @Autowired
    private RecommendService recommendService;

    @PostMapping("/add")
    @ApiOperation(value = "添加", notes = "添加推荐车辆")
    public ResultVO add(@RequestBody Recommend recommend) {
        int result = recommendService.add(recommend);
        if (result > 0) {
            return ResultVO.success("添加成功");
        }
        return ResultVO.error("添加失败，此车辆已存在推荐车辆中");
    }

    @DeleteMapping("/delete/{id}")
    @ApiOperation(value = "删除", notes = "删除推荐车辆")
    public ResultVO delete(@PathVariable("id") Integer id) {
        int result = recommendService.delete(id);
        if (result > 0) {
            return ResultVO.success("删除成功");
        }
        return ResultVO.error("删除失败");
    }

    @GetMapping("/findAllRecommendForManager")
    @ApiOperation(value = "管理员接口-查询全部推荐车辆", notes = "查询全部推荐车辆")
    public ResultVO findAllRecommendForManager() {
        return ResultVO.success("查询成功", recommendService.findAllRecommendForManager());
    }

    @GetMapping("/findAllRecommendForUser")
    @ApiOperation(value = "用户接口-查询全部推荐车辆", notes = "查询全部推荐车辆")
    public ResultVO findAllRecommendForUser() {
        return ResultVO.success("查询成功", recommendService.findAllRecommendForUser());
    }
}
